#有效的括号
class Solution:
    def isValid(self, s: str) -> bool:
        if len(s) % 2 != 0:
            return False
        mapping = {')': '(', ']': '[', '}': '{'}
        stack = []
        for char in s:
            if char in mapping.values():
                stack.append(char)
            else:
                if not stack:
                    return False
                top = stack.pop()
                if top != mapping[char]:
                    return False
        return len(stack) == 0